package com.theanh.RssActivity.util;

import java.util.ArrayList;
import java.util.List;

import com.theanh.RssActivity.Store;

public class Paging<T> {
	private int numberPage = 0; 
	private List<T> list;
	private int PAGE_SIZE = Store.setting.getPageSize();
	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		if (list == null || list.size() == 0){
			this.list = new ArrayList<T>();
			return;
		}else{
			this.list = list;
		}
		numberPage = list.size() / PAGE_SIZE;
		
		if (list.size() % PAGE_SIZE > 0)
			numberPage++;
	}

	public int getNumberPage() {
		return numberPage;
	}

	public Paging() {
	}

	public Paging(List<T> list) {
		if (list == null || list.size() == 0){
			this.list = new ArrayList<T>();
			return;
		}else{
			this.list = list;
		}
		numberPage = list.size() / PAGE_SIZE;
		
		if (list.size() % PAGE_SIZE > 0)
			numberPage++;
	}
	
	public List<T> getPage(int page){
		page--;
		if (page < 0 || page > numberPage)
			return new ArrayList<T>();
		
		List<T> result = new ArrayList<T>();
		for(int i = page * PAGE_SIZE; i < list.size(); i++){
			if ((page + 1) * PAGE_SIZE < i + 1)
				break;
			result.add(list.get(i));
		}
		return result;
	}
}
